package cn.hunqing.web.dto;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import cn.hunqing.web.entity.WeddingInvitation;

public class WeddingInvitationDto {
	private int weddingInvitationId;
	
    private String bridegroom;
    
    private String bride;
    
    private String weddingDay_Y;

    private String weddingDay_M;
    
    private String weddingDay_D;
    
    private String startTime_HR;
    
    private String startTime_MIN;
    
    private String countDown;
    
    private String hotel;
    
    private String address;
    
    private String coordinate;

    private boolean loveStoryPictureSelected;
    
    private String loveStoryPicture;
    
    private String loveStoryContent;

    private boolean loveStoryVideoSelected;
    
    private String loveStoryVideo;
    
    
    private String backgroundMusic;
    
    private List<String> weddingPhotos;
    
    private int isPayed;

	public int getWeddingInvitationId() {
		return weddingInvitationId;
	}

	public void setWeddingInvitationId(int weddingInvitationId) {
		this.weddingInvitationId = weddingInvitationId;
	}

	public String getBridegroom() {
		return bridegroom;
	}

	public void setBridegroom(String bridegroom) {
		this.bridegroom = bridegroom;
	}

	public String getBride() {
		return bride;
	}

	public void setBride(String bride) {
		this.bride = bride;
	}

	public String getWeddingDay_Y() {
		return weddingDay_Y;
	}

	public void setWeddingDay_Y(String weddingDay_Y) {
		this.weddingDay_Y = weddingDay_Y;
	}

	public String getWeddingDay_M() {
		return weddingDay_M;
	}

	public void setWeddingDay_M(String weddingDay_M) {
		this.weddingDay_M = weddingDay_M;
	}

	public String getWeddingDay_D() {
		return weddingDay_D;
	}

	public void setWeddingDay_D(String weddingDay_D) {
		this.weddingDay_D = weddingDay_D;
	}

	public String getStartTime_HR() {
		return startTime_HR;
	}

	public void setStartTime_HR(String startTime_HR) {
		this.startTime_HR = startTime_HR;
	}

	public String getStartTime_MIN() {
		return startTime_MIN;
	}

	public void setStartTime_MIN(String startTime_MIN) {
		this.startTime_MIN = startTime_MIN;
	}

	public String getHotel() {
		return hotel;
	}

	public void setHotel(String hotel) {
		this.hotel = hotel;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getCoordinate() {
		return coordinate;
	}

	public void setCoordinate(String coordinate) {
		this.coordinate = coordinate;
	}

	public String getLoveStoryPicture() {
		return loveStoryPicture;
	}

	public void setLoveStoryPicture(String loveStoryPicture) {
		this.loveStoryPicture = loveStoryPicture;
	}

	public String getLoveStoryVideo() {
		return loveStoryVideo;
	}

	public void setLoveStoryVideo(String loveStoryVideo) {
		this.loveStoryVideo = loveStoryVideo;
	}

	public String getLoveStoryContent() {
		return loveStoryContent;
	}

	public void setLoveStoryContent(String loveStoryContent) {
		this.loveStoryContent = loveStoryContent;
	}

	public String getBackgroundMusic() {
		return backgroundMusic;
	}

	public void setBackgroundMusic(String backgroundMusic) {
		this.backgroundMusic = backgroundMusic;
	}

	public List<String> getWeddingPhotos() {
		return weddingPhotos;
	}

	public void setWeddingPhotos(List<String> weddingPhotos) {
		this.weddingPhotos = weddingPhotos;
	}
    
    public String getCountDown() {
		return countDown;
	}

	public void setCountDown(String countDown) {
		this.countDown = countDown;
	}

	public boolean isLoveStoryPictureSelected() {
		return loveStoryPictureSelected;
	}

	public void setLoveStoryPictureSelected(boolean loveStoryPictureSelected) {
		this.loveStoryPictureSelected = loveStoryPictureSelected;
	}

	public boolean isLoveStoryVideoSelected() {
		return loveStoryVideoSelected;
	}

	public void setLoveStoryVideoSelected(boolean loveStoryVideoSelected) {
		this.loveStoryVideoSelected = loveStoryVideoSelected;
	}
	
	public int getIsPayed() {
		return isPayed;
	}

	public void setIsPayed(int isPayed) {
		this.isPayed = isPayed;
	}

	public static WeddingInvitationDto buildFrom(WeddingInvitation weddingInvitation){
    	if(weddingInvitation == null){
    		return null;
    	}
    	WeddingInvitationDto result = new WeddingInvitationDto();
    	result.setAddress(weddingInvitation.getAddress());
    	result.setBackgroundMusic(weddingInvitation.getBackgroundMusic());
    	result.setBride(weddingInvitation.getBride());
    	result.setBridegroom(weddingInvitation.getBridegroom());
    	result.setCoordinate(weddingInvitation.getCoordinate());
    	result.setHotel(weddingInvitation.getHotel());
    	result.setLoveStoryContent(weddingInvitation.getLoveStoryContent());
    	result.setLoveStoryPictureSelected(weddingInvitation.getLoveStoryPictureSelected());
    	result.setLoveStoryPicture(weddingInvitation.getLoveStoryPicture());
    	result.setLoveStoryVideoSelected(weddingInvitation.getLoveStoryVideoSelected());
    	result.setLoveStoryVideo(weddingInvitation.getLoveStoryVideo());
		result.setWeddingDay_Y(weddingInvitation.getWeddingDay_Y());   
		result.setWeddingDay_M(weddingInvitation.getWeddingDay_M());   
	    result.setWeddingDay_D(weddingInvitation.getWeddingDay_D());  
    	result.setStartTime_HR(weddingInvitation.getStartTime_HR());
    	result.setStartTime_MIN(weddingInvitation.getStartTime_MIN());
    	result.setWeddingInvitationId(weddingInvitation.getId());
    	result.setIsPayed(weddingInvitation.getIsPayed());
    	if(!StringUtils.isEmpty(weddingInvitation.getWeddingPhotos())){
    		String[] photos = StringUtils.split(weddingInvitation.getWeddingPhotos(), "|");
    		if(photos != null){
    			List<String> photoList = new ArrayList<>();
        		for(int i = 0; i< photos.length ; i ++){
        			String photo = photos[i];
        			photo = StringUtils.trimToNull(photo);
        			if(!StringUtils.isEmpty(photo)){
            			photoList.add(photo);
        			}
        		}
            	result.setWeddingPhotos(photoList);
    		}
    	}
    	DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");  
		try {
			Date weddingDate = format1.parse(weddingInvitation.getWeddingDay_Y()+"-"+weddingInvitation.getWeddingDay_M()+"-"+weddingInvitation.getWeddingDay_D());
			long differ=weddingDate.getTime() - (new Date()).getTime();
			long day =differ / (24*60*60*1000);
			result.setCountDown(String.valueOf(day));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
    	return result;
    }
}
